home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / prog_disc / volume_5 / issue_06 / benchmarks / c_source / whet < prev   
Encoding:
Text File  |  1991-06-04  |  4.2 KB  |  203 lines

  1. /*    Whetstone benchmark. Used for compile comparison. This program
  2.     has a long history and is well described in "A Synthetic Benchmark"
  3.     by H.J. Curnow and B.A. Wichman in Computer Journal, Vol 19 #1,
  4.     Feburary 1976.
  5.  
  6.     Time the compiles with and without the optimizer as follows:
  7.  
  8.     time cc -o whet whet.c -lm
  9.     time cc -O -o whet.opt whet.c -lm
  10.  
  11.     Then time the runs of both versions as follows:
  12.  
  13.     time whet
  14.     time whet.opt
  15. */
  16.  
  17. #define ITERATIONS    2
  18. #define PNT5MINUS    0.499975
  19. #define PNT5PLUS    0.50025
  20. #define TWO        2.0
  21.  
  22. #include <math.h>
  23. #include "timer.h"
  24.  
  25. main()
  26. {
  27. static int    mod1freq, mod2freq, mod3freq, mod4freq, mod6freq;
  28. static int    mod7freq, mod8freq, mod9freq, mod10freq, mod11freq;
  29. static double     ary[4];
  30. static double    real1, real2, real3, real4;
  31. register int     cntr;
  32. register int    int1, int2, int3;
  33.  
  34. init_timer();
  35. start_timer();
  36. /* Establish execution frequencies */
  37.  
  38. mod1freq = 0 * ITERATIONS;
  39. mod2freq = 12 * ITERATIONS;
  40. mod3freq = 14 * ITERATIONS;
  41. mod4freq = 345 * ITERATIONS;
  42. mod6freq = 210 * ITERATIONS;
  43. mod7freq = 32 * ITERATIONS;
  44. mod8freq = 899 * ITERATIONS;
  45. mod9freq = 616 * ITERATIONS;
  46. mod10freq = 0 * ITERATIONS;
  47. mod11freq = 93 * ITERATIONS;
  48.  
  49. /* Module 1: simple identifiers */
  50.  
  51. real1 = 1.0;
  52. real2 = -1.0;
  53. real3 = -1.0;
  54. real4 = -1.0;
  55. for(cntr = 1; cntr <= mod1freq; cntr += 1)
  56.     {
  57.     real1 = (real1 + real2 + real3 - real4) * PNT5MINUS;
  58.     real2 = (real1 + real2 - real3 - real4) * PNT5MINUS;
  59.     real3 = (real1 - real2 + real3 + real4) * PNT5MINUS;
  60.     real4 = (real2 - real1 + real3 + real4) * PNT5MINUS;
  61.     } /* for */
  62.  
  63. /* Module 2: array elements */
  64.  
  65. ary[1] = 1.0;
  66. ary[2] = -1.0;
  67. ary[3] = -1.0;
  68. ary[4] = -1.0;
  69. for(cntr = 1; cntr <= mod2freq; cntr += 1)
  70.     {
  71.     ary[1] = (ary[1] + ary[2] + ary[3] - ary[4]) * PNT5MINUS;
  72.     ary[2] = (ary[1] + ary[2] - ary[3] + ary[4]) * PNT5MINUS;
  73.     ary[3] = (ary[1] - ary[2] + ary[3] + ary[4]) * PNT5MINUS;
  74.     ary[4] = (ary[2] - ary[1] + ary[3] + ary[4]) * PNT5MINUS;
  75.     } /* for */
  76.  
  77.  
  78. /* Module 3: array as parameter ( see program at end ) */
  79.  
  80. for(cntr = 1; cntr <= mod3freq; cntr += 1)
  81.     mod3(ary);
  82.  
  83. /* Module 4: conditional jumps */
  84.  
  85. int1 = 1;
  86. for(cntr = 1; cntr <= mod4freq; cntr += 1)
  87.     {
  88.     if(int1 == 1)
  89.         int1 = 2;
  90.     else
  91.         int1 = 3;
  92.     if (int1 > 2)
  93.         int1 = 0;
  94.     else
  95.         int1 = 1;
  96.  
  97.     if (int1 < 1)
  98.         int1 = 1;
  99.     else
  100.         int1 = 0;
  101.     } /* for */
  102.  
  103. /* Module 6: integer arithmetic using arrays */
  104.  
  105. int1 = 1;
  106. int2 = 2;
  107. int3 = 3;
  108. for(cntr = 1; cntr <= mod6freq; cntr += 1)
  109.     {
  110.     int1 = int1 * (int2 - int1) * (int3 - int2);
  111.     int2 = int3 * int2 - (int3 - int1) * int2;
  112.     int3 = (int3 - int2) * (int2 + int1);
  113.  
  114.     ary[int3 - 1] = int1 + int2 + int3;
  115.     ary[int2 - 1] = int1 * int2 * int3;
  116.     }
  117.  
  118. /* Module 7: trigonometric functions */
  119.  
  120. real1 = 0.5;
  121. real2 = 0.5;
  122. for(cntr = 1; cntr <= mod7freq; cntr += 1)
  123.     {
  124.     real1 = atan(TWO * sin(real1) * cos(real1) / (cos(real1 + real2) + 
  125.         cos(real1 - real2) - 1.0)) * PNT5MINUS;
  126.     real2 = atan(TWO * sin(real2) * cos(real2) / (cos(real1 + real2) + 
  127.         cos(real1 - real2) - 1.0)) * PNT5MINUS;
  128.     }
  129.  
  130. /* Module 8: procedure calls */
  131.  
  132. real1 = real2 = real3 = 1.0;
  133. for(cntr = 1; cntr <= mod8freq; cntr += 1)
  134.     mod8(real1, real2, &real3);
  135.  
  136. /* Module 9: array references */
  137. int1 = 1;
  138. int2 = 2;
  139. int3 = 3;
  140. ary[1] = 1.0;
  141. ary[2] = 2.0;
  142. ary[3] = 3.0;
  143. for(cntr = 1; cntr <= mod9freq; cntr += 1)
  144.     {
  145.     ary[int1] = ary[int2];
  146.     ary[int2] = ary[int3];
  147.     ary[int3] = ary[int1];
  148.     }
  149.  
  150. /* Module 10: integer arithmetic */
  151.  
  152. int1 = 2;
  153. int2 = 3;
  154. for(cntr = 1; cntr <= mod10freq; cntr += 1)
  155.     {
  156.     int1 = int1 + int2;
  157.     int2 = int1 + int2;
  158.     int1 = int2 - int1;
  159.     int2 = int2 - int1 - int1;
  160.     }
  161.  
  162. /* Module 11: standard functions */
  163.  
  164. real1 = 0.75;
  165. for(cntr = 1; cntr <= mod11freq; cntr += 1)
  166.     real1= sqrt( exp( log(real1) / PNT5PLUS));
  167.  
  168. print_elapsed("Whetstone floating point benchmark",REALMIN,USERMIN, SYSTEMMIN);
  169. exit(0);
  170. /* end of main program */
  171. }
  172.  
  173. /* Module 3 routine */
  174.  
  175. mod3(a)
  176. double a[4];
  177.  
  178. {
  179. int cntr;
  180. for(cntr = 0; cntr <= 6; cntr += 1)
  181.     {
  182.     a[1] = (a[1] + a[2] + a[3] - a[4]) * PNT5MINUS;
  183.     a[2] = (a[1] + a[2] - a[3] + a[4]) * PNT5MINUS;
  184.     a[3] = (a[1] - a[2] + a[3] + a[4]) * PNT5MINUS;
  185.     a[4] = (-a[1] + a[2] + a[3] + a[4]) / TWO;
  186.     } /* for */
  187. }
  188.  
  189. /* Module 8 routine */
  190.  
  191. mod8(r1, r2, r3)
  192. double r1, r2, *r3;
  193. {
  194.     double tmp1, tmp2;
  195.  
  196.     tmp1 = r1;
  197.     tmp2 = r2;
  198.  
  199.     tmp1 = PNT5MINUS * (tmp1 + tmp2);
  200.     tmp2 = PNT5MINUS * (tmp1 + tmp2);
  201.     *r3 = (tmp1 + tmp2) / TWO;
  202. }
  203.